<script type="text/javascript" language="JavaScript">
	$(function(){
		/* khởi tạo popup */
        $('input[rel*=menu_popup]').showPopup({
			scroll : false, //cho phép scroll khi mở popup, mặc định là không cho phép
        	onClose:function(){            	
        		//sự kiện cho phép gọi sau khi đóng popup, cho phép chúng ta gọi 1 số sự kiện khi đóng popup, bạn có thể để null ở đây
        	}
        });	
	});
	(function(a){
		a.fn.extend({
			showPopup:function(b){
				function f(c){
					if(b.onClose instanceof Function)b.onClose();
					a("#lean_overlay").fadeOut(200);
					a(c).css({display:"none"})}
				var e=a("<div id='lean_overlay'></div>");
					a("body").append(e);
					b=a.extend({top:100,overlay:0.5,scroll:!0,closeButton:null},b);
					return this.each(function(){var c=b;a(this).click(function(b){
						var d=a(this).attr("href");
						a("#lean_overlay").click(function(){f(d)});
						a(c.closeButton).click(function(){f(d)});
						a(d).outerHeight();
						var e=a(d).outerWidth();
						a("#lean_overlay").css({display:"block",opacity:0});
						a("#lean_overlay").fadeTo(200,c.overlay);
						a(d).css({display:"block",position:"absolute",opacity:0,"z-index":110,left:"45%","margin-left":-(e/2)-30+"px",top:40+"px"});
						c.scroll&&(a("html").css({overflow:"hidden"}),a("body").css({overflow:"hidden"}));
						a(d).fadeTo(200,1);
						b.preventDefault()
					})
				})
			}
		})
	})(jQuery);
</script>
<style>
	#open_popup {
		color: #FEF4E9;
		background: rgb(125,185,232); /* Old browsers */
		background: -moz-linear-gradient(top,  rgba(125,185,232,1) 0%, rgba(32,124,202,1) 49%, rgba(41,137,216,1) 50%, rgba(30,87,153,1) 100%); /* FF3.6+ */
		background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(125,185,232,1)), color-stop(49%,rgba(32,124,202,1)), color-stop(50%,rgba(41,137,216,1)), color-stop(100%,rgba(30,87,153,1))); /* Chrome,Safari4+ */
		background: -webkit-linear-gradient(top,  rgba(125,185,232,1) 0%,rgba(32,124,202,1) 49%,rgba(41,137,216,1) 50%,rgba(30,87,153,1) 100%); /* Chrome10+,Safari5.1+ */
		background: -o-linear-gradient(top,  rgba(125,185,232,1) 0%,rgba(32,124,202,1) 49%,rgba(41,137,216,1) 50%,rgba(30,87,153,1) 100%); /* Opera 11.10+ */
		background: -ms-linear-gradient(top,  rgba(125,185,232,1) 0%,rgba(32,124,202,1) 49%,rgba(41,137,216,1) 50%,rgba(30,87,153,1) 100%); /* IE10+ */
		background: linear-gradient(to bottom,  rgba(125,185,232,1) 0%,rgba(32,124,202,1) 49%,rgba(41,137,216,1) 50%,rgba(30,87,153,1) 100%); /* W3C */
		filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#7db9e8', endColorstr='#1e5799',GradientType=0 ); /* IE6-9 */
		float:right;
		text-align: center;
		text-decoration: none;
		font: 13px Arial, Helvetica, sans-serif;
		width:50px;
		height:25px;
		margin-top:4px;
		text-shadow:0px 0px 4px #ffffff;
		-moz-border-radius: 1em 1em 1em 1em;
		-webkit-border-radius: 1em 1em 1em 1em;
		border-radius: 1em 1em 1em 1em;
	}
</style>
<?php 
	function check_popup_child($id_cha)
	{
		$tv="select count(*) from category where parent_id='$id_cha'";
		$tv_1=mysql_query($tv);
		$tv_2=mysql_fetch_row($tv_1);
		if($tv_2[0]==0)
		{
			return "khong";
		}
		else 
		{
			return "co";
		}
	}
	function recursive_popup($id_cha)
	{
		//Nguyen Manh Gia Thong Nov 15 2012------------------//
		$tv="select * from category a where a.parent_id='$id_cha' ";
		//$tv="select * from category a, category_description b where a.parent_id='$id_cha' and a.category_id=b.category_id";
		//-------------------------------//
		$tv_1=mysql_query($tv);
		while($tv_2=mysql_fetch_array($tv_1))
		{
			$link=$tv_2['parent_id'];
			$link2=$tv_2['category_id'];
			echo "<li class='children'>";
				echo "<a href=index.php?route=product/category&path=";
				echo "$link";
				echo "_";
				echo "$link2";
				echo ">";
					echo "<img src=catalog/view/theme/default/image/bullet_2.png> ";
					echo $tv_2['name'];
				echo "</a>";
				$check_popup_child=check_popup_child($tv_2['category_id']);
				if($check_popup_child=="co")
				{				
					echo "<ul>";
						recursive_popup($tv_2['category_id']);
					echo "</ul>";
										
				}
			echo "</li>";
		}	
	}
?>
<input type="button" id="open_popup" name="open_popup" rel="menu_popup" href="#popup_content" value="Tất cả">
<div id="popup_content" class="popup" style="display: none; position: fixed; opacity: 1; z-index: 110; left: 50%; margin-left: -202px; top: 200px; ">
	<div class="popup-header">
		Danh mục sản phẩm
	</div>
	<div class="info_popup">
			<?php 
			//Nguyen Manh Gia Thong Nov 15 2012---------------------/
				$tv="select * from category a where a.parent_id='0' and name is not NULL ";
				//$tv="select * from category a, category_description b where a.parent_id='0' and a.category_id=b.category_id";
			//-------------------------------------------------------/
				$tv_1=mysql_query($tv);
				while($tv_2=mysql_fetch_array($tv_1))
				{
					echo "<ul id='popup_child'>";
					echo "<li class='title_popup'>";					
						echo "<a href='$link'>";
							echo $tv_2['name'];
						echo "</a></li>";
						$check_popup_child=check_popup_child($tv_2['category_id']);
						if($check_popup_child=="co")
						{
										recursive_popup($tv_2['category_id']);
						}
					echo "</ul>";
				}
			?>
	</div>

</div>
<div id="lean_overlay" style="display: none; opacity: 0.5; "></div>